﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Common;
using WF_Business;

namespace ExtBusiness.User
{
    /// <summary>
    /// 用户登录操作类
    /// </summary>
    public class UserLogin
    {
        /// <summary>
        /// 根据用户名和密码获取相关信息
        /// </summary>
        /// <param name="loginName">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="strJiaMiPass">加密后的pass</param>
        /// <returns></returns>
        public DataSet GetUserIdAndName(string loginName, string password,string strJiaMiPass)
        {
            string strSql = string.Format("select userid,user_name from st_user where login_name='{0}' and (password='{1}' or password='{2}' or password='{3}')",
                  loginName, password, Encode.Md5(password),strJiaMiPass);

            DataSet dsOut = null;
            SysParams.OAConnection().RunSql(strSql, out dsOut);
            return dsOut;
        }

        /// <summary>
        /// 根据用户id获取角色id
        /// </summary>
        /// <param name="userid">用户id</param>
        /// <returns></returns>
        public string GetGroupId(string userid)
        {
            string strSql = "select gid from st_user_group where userid='" + userid + "'";
            return SysParams.OAConnection().GetValue(strSql);
        }

        /// <summary>
        /// 校验用户信息
        /// </summary>
        /// <param name="userid">用户id</param>
        /// <returns></returns>
        public DataSet ValideUser(string userid)
        {
            string strSql = "select * from st_user where userid='" + userid + "'";
            DataSet dsOut = null;
            SysParams.OAConnection().RunSql(strSql, out dsOut);
            return dsOut;
        }

        /// <summary>
        /// 根据loginName获取用户信息
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public DataTable GetUserInfoByLoginName(string userid)
        {
            string strSql = string.Format("select * from st_user where LOGIN_NAME='{0}'",userid);
            DataTable dtOut = null;
            SysParams.OAConnection().RunSql(strSql, out dtOut);
            return dtOut;
        }


    }
}
